/*
 *  Netzpult - Your desk on the web
 *  Copyright (C) 2011  Ulrich Hilger, http://uhilger.de
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/
 */

package de.uhilger.netzpult.shared;

import java.io.Serializable;
import java.util.Date;

import de.uhilger.baselink.DBColumn;
import de.uhilger.baselink.DBPrimaryKey;
import de.uhilger.baselink.DBTable;

/**
 * ArchivedDocument 
 * 
 * @author Copyright (c) Ulrich Hilger, http://uhilger.de
 * @author Published under the terms and conditions of
 * the <a href="http://www.gnu.org/licenses/" target="_blank">GNU General Public License</a>
 */
@DBTable(name = "webfiles.document_archive")
@DBPrimaryKey({"da_id","da_version"})
public class ArchivedDocument implements Serializable, Comparable<ArchivedDocument> {

	private static final long serialVersionUID = -5203475717608462778L;
	
	private Document doc;
	
	public ArchivedDocument() {
		super();
	}
	
	public ArchivedDocument(Document d) {
		this.doc = d;
	}
	
	public void setDocument(Document d) {
		this.doc = d;
	}
	
	public Document getDocument() {
		return doc;
	}

	public String getCreationTimeStr() {
		return doc.getCreationTimeStr();
	}

	public int getOrder() {
		return doc.getOrder();
	}

	public void setOrder(int order) {
		doc.setOrder(order);
	}

	@DBColumn(name = "da_id")
	public int getId() {
		return doc.getId();
	}

	public void setId(int id) {
		doc.setId(id);
	}

	public Date getCreationDateTime() {
		return doc.getCreationDateTime();
	}

	public void setCreationDateTime(Date creationDateTime) {
		doc.setCreationDateTime(creationDateTime);
	}

	@DBColumn(name = "da_title")
	public String getTitle() {
		return doc.getTitle();
	}

	public void setTitle(String title) {
		doc.setTitle(title);
	}

	@DBColumn(name="da_content", type=DBColumn.Type.BLOB)
	public String getContent() {
		return doc.getContent();
	}

	public void setContent(String html) {
		doc.setContent(html);
	}

	@DBColumn(name = "da_timestamp")
	public String getCreationTime() {
		return doc.getCreationTime();
	}

	public void setCreationTime(String creationTime) {
		doc.setCreationTime(creationTime);
	}
		
	public Date getDocumentDate(String creationTime) {
		return doc.getDocumentDate(creationTime);
	}

	@DBColumn(name = "da_version")
	public int getVersion() {
		return doc.getVersion();
	}

	public void setVersion(int version) {
		doc.setVersion(version);
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof ArchivedDocument) {
			return (getId() == ((ArchivedDocument) obj).getId());
		}
		return false;
	}

	@Override
	public int compareTo(ArchivedDocument o) {
		return this.getTitle().compareTo(o.getTitle());
	}
	
	@DBColumn(name = "da_mimetype")
	public String getMimeType() {
		return doc.getMimeType();
	}

	public void setMimeType(String mimeType) {
		doc.setMimeType(mimeType);
	}	
}
